﻿<!-- 考试管理-考试日程 -->
<style>
    .modal .el-card__body {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
</style>
<template>
    <div>
        <!-- 添加按钮 -->
        <div class="btn-add">
            <button type="button" class="btn btn-success btn-lg" @click="apks()"><i class="iconfont icon-chenggong ft12 mr5"></i>安排考试</button>
            <button type="button" class="btn btn-danger btn-lg" @click="qxap()"><i class="iconfont icon-chexiao ft12 mr5"></i>取消考试安排</button>
        </div>
        <!-- 按条件选择 -->

        <el-row :gutter="20" style="height:100px;padding:20px;">
            <el-col :span="4">
                <div class="input-group" style="margin-bottom:10PX;">
                    <div class="input-group-btn">
                        <button type="button" style="height: 34px;min-width:80PX" class="btn btn-primary  dropdown-toggle">考试类别</button>
                    </div>
                    <el-select placeholder="考试类别" size="mini" v-model="query.lx" class="form-control filter" style="height: 34px;padding:0px">
                        <el-option label="补考" value="补考"></el-option>
                    </el-select>

                </div>
            </el-col>
            <el-col :span="4">
                <div class="input-group" style="margin-bottom:10PX;">
                    <div class="input-group-btn">
                        <button type="button" style="height: 34px;min-width:80PX" class="btn btn-primary  dropdown-toggle">考试学期</button>
                    </div>
                    <base-xq :pzoption="query.xq"></base-xq>

                </div>
            </el-col>
            <el-col :span="6">
                <div class="input-group" style="margin-bottom:10PX;">
                    <div class="input-group-btn">
                        <button type="button" style="height: 34px;min-width:80PX" class="btn btn-primary  dropdown-toggle">班级系部</button>
                    </div>
                    <base-xb :pzoption="query.xb" isqx isjx isdx></base-xb>
                </div>
            </el-col>
            <el-col :span="4">
                <div class="input-group hide" style="margin-bottom:10PX;">
                    <div class="input-group-btn">
                        <button type="button" style="height: 34px;min-width:80PX" class="btn btn-primary  dropdown-toggle">课程安排情况</button>
                    </div>
                    <el-select placeholder="课程安排情况" size="mini" v-model="query.apqk" class="form-control filter" style="height: 34px;padding:0px">
                        <el-option label="全部" value=""></el-option>
                        <el-option label="待安排" value="已安排"></el-option>
                        <el-option label="已安排" value="已安排"></el-option>

                    </el-select>

                </div>
            </el-col>
            <el-col :span="6">
            </el-col>
        </el-row>

        <el-row :gutter="20" style="padding:20px;   padding-top: 0px;">
            
            <el-col :span="24">
                <p class="text-danger" style="margin-bottom:5px">选择需要安排考试的人员</p>
                <base-table :pzoption="tableop" @selection-change="rychange">
                </base-table>
            </el-col>
        </el-row>


        <div class="modal fade dx" id="DModal" role="dialog">
            <div class="modal-dialog" role="document" style="width: 1100px">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">
                            安排考试信息
                        </h4>
                    </div>
                    <div class="modal-body">
                        <el-row :gutter="12" style="padding: 0 20px;">
                            <el-col :span="12">
                                <el-tooltip class="item" effect="dark"  :content="bjs" placement="bottom-end">
                                    <el-card shadow="hover">
                                        安排班级：{{bjs}}
                                    </el-card>
                                </el-tooltip>

                            </el-col>
                            <el-col :span="6">
                                <el-tooltip class="item" effect="dark" :content="kcs" placement="bottom-end">
                                    <el-card shadow="hover">
                                        安排课程：{{kcs}}
                                    </el-card>
                                </el-tooltip>

                            </el-col>
                            <el-col :span="6">
                                <el-card shadow="hover">
                                    安排考生数量:<span class="text-danger">{{kss}}</span>
                                </el-card>
                            </el-col>
                        </el-row>
                        <el-row :gutter="20" style="padding:20px">
                            <el-col :span="14">
                                <p class="text-danger" style="margin-bottom:5px">考试时间：{{selsj.sj}}</p>
                                <pl-table class="qjTable" :data="sjdata" height="450px" :row-style="{height:'20px'}" :cell-style="{padding:'0px'}" element-loading-background="rgba(0, 0, 0, 0.8)" stripe border fit use-virtual big-data-checkbox>
                                    <pl-table-column prop="ksz" width="100" label="考试周" sortable>
                                    </pl-table-column>
                                    <pl-table-column prop="zc" width="100" label="星期" sortable>
                                    </pl-table-column>
                                    <pl-table-column prop="jc1" label="节次" width="80" sortable>
                                        <template slot-scope="scope">
                                            <span>{{scope.row.jc1}}~{{scope.row.jc2}}</span>
                                        </template>
                                    </pl-table-column>
                                    <pl-table-column prop="sj" label="考试时间" sortable>
                                    </pl-table-column>
                                    <pl-table-column label="选中"
                                                     width="80">
                                        <template slot-scope="scope">
                                            <!--<el-button @click="handleClick(scope.row)" type="text" size="small">选中</el-button>-->
                                            <el-radio @change="handleClick(scope.row)" v-model="rselsj" :label="scope.row.sj">选中</el-radio>
                                        </template>
                                    </pl-table-column>
                                </pl-table>

                            </el-col>
                            <el-col :span="10">
                                <p class="text-danger" style="margin-bottom:5px">选择教室：{{seljs.jse}}-{{seljs.gn}}</p>
                                <div class="input-group" style="width:520PX;margin-bottom:10PX;">
                                    <div class="input-group-btn">
                                        <button type="button" style="min-width:120PX;height: 34px;" class="btn btn-info  dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">搜索教室</button>
                                    </div>
                                    <el-input style="height: 34px;border-left-width: 0px;width:250px" size="medium" placeholder="输入教室名称搜索" v-model="seastrjs" clearable></el-input>

                                </div>

                                <pl-table class="qjTable" :data="comjsdata " height="450px" :row-style="{height:'20px'}" :cell-style="{padding:'0px'}" element-loading-background="rgba(0, 0, 0, 0.8)" highlight-current-row stripe border fit use-virtual big-data-checkbox>
                                    <pl-table-column type="index" width="60" fixed="left"> </pl-table-column>
                                    <pl-table-column prop="jse" label="教室" width="150" sortable>
                                        <template slot-scope="scope">
                                            <el-tag type="primary" disable-transitions>{{scope.row.jse}}-{{scope.row.gn}}</el-tag>
                                        </template>
                                    </pl-table-column>
                                    <pl-table-column prop="kszw" label="座位数量" sortable>
                                    </pl-table-column>

                                    <pl-table-column label="选中"
                                                     width="80">
                                        <template slot-scope="scope">
                                            <!--<el-button @click="handleClick(scope.row)" type="text" size="small">选中</el-button>-->
                                            <el-radio @change="seljse(scope.row)" v-model="rseljs" :label="scope.row.jse">选中</el-radio>
                                        </template>
                                    </pl-table-column>
                                </pl-table>
                            </el-col>
                        </el-row>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-info" @click="SaveData()">确认</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    module.exports = {
        props: ['pdata'],
        components: {
            'base-table': httpVueLoader('/ViewV5/Base/Vue/Table.vue'),
            'base-xq': httpVueLoader('/ViewV5/AppPage/QJJW/component/conxq.vue'),
            'base-xb': httpVueLoader('/ViewV5/AppPage/QJJW/component/conxb.vue?v=2'),

        },
        data: function () {
            return {
                search: "",
                seastrkc: "",
                seastrjs:"",
                kcdm: "",
                jssl: 0,
                allxsdata: [],//学生数据
                allkcdata: [],//所有课程
                sjdata: [],//时间
                jsdata: [],//教室
                selsj: {},//选中时间
                seljs: {},//选中教师
                rselsj: "",
                rseljs: "",
                loading: false,
                query: {
                    lx: "补考",
                    qrzt: "",
                    apqk: "",
                    xb: { value: [] },
                    xq: { value: "" },
                },
                js: { value: "" },
                seljc: { jcmc: "", isbn: "" },
                tableop: {
                    title: "考生信息",
                    issel: true,
                    iscz: false,
                    height: 480,
                    isxh: true,
                    dataset: [],
                    loading: false,
                    multipleSelection: [],
                    collist: [
                        { colid: "kcmc", colname: "课程名称", isshow: true, istip: true },
                        { colid: "kcdm", colname: "课程代码", isshow: false, istip: true },
                        { colid: "jsmc", colname: "教师名称", isshow: true, istip: true },
                        { colid: "kcxbmc", colname: "课程系部", isshow: false, istip: true },
                        { colid: "zbmc", colname: "班级系部", isshow: false, istip: true },
                        { colid: "bj", colname: "班级", isshow: true, istip: true },
                        { colid: "xh", colname: "学号", isshow: false, istip: true, nosort: true },
                        { colid: "xm", colname: "姓名", isshow: true, istip: true, nosort: true },
                        { colid: "sj", colname: "考试时间", isshow: true, istip: false, nosort: true, width: "180" },
                        { colid: "bkjse", colname: "考试教室", isshow: true, istip: true, nosort: true }
                        //{ colid: "bjrs", colname: "考场", isshow: true, istip: true, nosort: true },


                    ]
                }
            }
        },
        computed: {
            kss: function () {
                return this.tableop.multipleSelection.length;
            },
            bjs: function () {
                var bjs = "";
                _.forEach(this.tableop.multipleSelection, function (obj) {
                    if (bjs.indexOf(obj.bj) == -1) {
                        bjs = bjs + obj.bj + ",";
                    }
                })
                return bjs;
            },
            kcs: function () {
                var kcs = "";
                _.forEach(this.tableop.multipleSelection, function (obj) {
                    if (kcs.indexOf(obj.kcmc) == -1) {
                        kcs = kcs + obj.kcmc + ",";
                    }
                })
                return kcs;
            },
            comkcdata: function () {
                var pro = this;
                if (pro.seastrkc) {
                    return _.filter(pro.allkcdata, function (obj) {
                        return (obj.kcmc.indexOf(pro.seastrkc) > -1 || obj.jsmc.indexOf(pro.seastrkc) > -1);
                    })
                } else {
                    return pro.allkcdata;
                }
            },
            comjsdata: function () {
                var pro = this;
                if (pro.seastrjs) {
                    return _.filter(pro.jsdata, function (obj) {
                        return obj.jse.indexOf(pro.seastrjs) > -1;
                    })
                } else {
                    return pro.jsdata;
                }
            }
        },
        methods: {
            filterTag(value, row) {
                return row.zt == value;
            },
            selchangekc: function (val, taa) {
                var pro = this;
                var kcs = [];
                var jsmc = [];
                for (var i = 0; i < val.length; i++) {
                    kcs.push(val[i].kcmc);
                    jsmc.push(val[i].jsmc);

                }
                if (kcs.length >= 0) {
                    var xsdatas = pro.allxsdata.filter(data => {
                        var bl = false;
                        for (var i = 0; i < kcs.length; i++) {
                            if (data["kcmc"] == kcs[i] && data["jsmc"] == jsmc[i]) {
                                bl = true;
                                break;
                            }
                        }
                        return bl;
                    })
                    pro.tableop.dataset = xsdatas;
                }
            },
            rychange(val) {
                this.tableop.multipleSelection = val;
            },
            handleClick: function (rowdata) {
                var pro = this;
                pro.selsj = rowdata;
                pro.seljs = {};
                pro.jsdata = [];
                pro.rseljs = "";
                $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_GETKJSBYSJ', { P1: rowdata.sjxx, xq: pro.query.xq.value, rs: "30" }, function (resultData) {
                    if (!resultData.ErrorMsg) {
                        pro.jsdata = resultData.Result;
                    }
                })
            },
            seljse: function (rowdata) {
                this.seljs = rowdata;
            },
            apks: function () {
                var pro = this;
                var ids = [];
                for (var i = 0; i < this.tableop.multipleSelection.length; i++) {
                    ids.push(this.tableop.multipleSelection[i].xh);
                }
                if (ids.length == 0) {
                    this.$notify.error({
                        title: '错误',
                        message: '至少需要选择一条数据才能操作'
                    });
                    return;
                }
                $('#DModal').modal('show');
            },
            qxap: function () {
                var pro = this;
                var ids = [];
                for (var i = 0; i < this.tableop.multipleSelection.length; i++) {
                    ids.push(this.tableop.multipleSelection[i].idn);
                }
                if (ids.length == 0) {
                    this.$notify.error({
                        title: '错误',
                        message: '至少需要选择一条数据才能操作'
                    });
                    return;
                }
                pro.$confirm('是否确认要取消考试安排?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_CANCELBK', { ids: ids.join() }, function (resultData) {
                        if (!resultData.ErrorMsg) {
                            pro.$notify({
                                title: '成功',
                                message: '操作成功',
                                type: 'success'
                            });
                            _.forEach(pro.tableop.dataset, function (obj) {
                                obj.bkjse = '';
                                obj.sj = "";

                            })
                        }
                    })
                }).catch(() => {
                    pro.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });



            },
            SaveData: function () {
                var pro = this;
                var ids = [];
                for (var i = 0; i < pro.tableop.multipleSelection.length; i++) {
                    ids.push(pro.tableop.multipleSelection[i].idn);
                }
                $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_SETBK', { ids: ids.join(), P1: pro.selsj.sjxx, jse: pro.seljs.jse }, function (resultData) {
                    if (!resultData.ErrorMsg) {
                        pro.$notify({
                            title: '成功',
                            message: '操作成功',
                            type: 'success'
                        });
                        _.forEach(pro.tableop.dataset, function (obj) {
                            obj.bkjse = pro.seljs.jse;
                            obj.sj = pro.selsj.sj;

                        })

                        $('#DModal').modal('hide');

                    }
                })
            },
            querydata: function () {
                var pro = this;
                pro.loading = true;
                $.getJSON('/API/VIEWAPI.ashx?Action=KSGL_GETDBKSJ', { P1: "1", xq: pro.query.xq.value, xb: pro.query.xb.value.join() }, function (resultData) {
                    if (!resultData.ErrorMsg) {
                        pro.allxsdata = resultData.Result;
                        pro.allkcdata = resultData.Result1;
                        pro.sjdata = resultData.Result2;
                        pro.loading = false;

                    }
                })

            }
        },
        watch: {
            'query': { //深度监听，可监听到对象、数组的变化
                handler(newV, oldV) {
                    var chi = this;
                    if (newV) {
                        if (chi.query.xb.value.length > 0) {
                            chi.querydata();
                        }
                    }
                },
                deep: true
            }
        },
        mounted: function () {
            var pro = this;
            pro.$nextTick(function () {
            })

        }
    };
</script>